﻿/*
  In App.xaml:
  <Application.Resources>
      <vm:ViewModelLocatorTemplate xmlns:vm="clr-namespace:TestApp.ViewModel"
                                   x:Key="Locator" />
  </Application.Resources>
  
  In the View:
  DataContext="{Binding Source={StaticResource Locator}, Path=ViewModelName}"
*/

using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Ioc;
using Microsoft.Practices.ServiceLocation;
using System;
using TestApp.Model;
using TestApp.Navigation;
using TestApp.ViewModel.PagesViewModels;
using TestApp.Utils;
using TestApp.Resources;
using System.Collections.Generic;


namespace TestApp.ViewModel
{
    /// <summary>
    /// This class contains static references to all the view models in the
    /// application and provides an entry point for the bindings.
    /// <para>
    /// See http://www.galasoft.ch/mvvm
    /// </para>
    /// </summary>
    public class ViewModelLocator
    {
        // URI to Pages
        public static readonly Uri CouponsListPage = new Uri("/View/CouponsListPage.xaml", UriKind.Relative);
        public const string CouponsDetailsPage = "/View/CouponDetailsPage.xaml";
        public static readonly Uri WebBrowserPage = new Uri("/View/WebBrowserPage.xaml", UriKind.Relative);
        public static readonly Uri StoresPage = new Uri("/View/StoresPage.xaml", UriKind.Relative);

        static ViewModelLocator()
        {
            ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default);
            
            // Home View Models
            SimpleIoc.Default.Register<PlanningViewModel>();
            SimpleIoc.Default.Register<ShoppingViewModel>();
            SimpleIoc.Default.Register<MoreViewModel>();

            // Coupons
            SimpleIoc.Default.Register<CouponsListViewModel>();
            SimpleIoc.Default.Register<CouponDetailsViewModel>(() => new CouponDetailsViewModel());

            // Stores
            SimpleIoc.Default.Register<StoresViewModel>();

            // WebBrowser
            SimpleIoc.Default.Register<WebBrowserViewModel>();
            
            // Register Navigation
            SimpleIoc.Default.Register<INavigationService, NavigationService>();

            // Register Localized Strings
            SimpleIoc.Default.Register<Localization>();

            // Register Graphi
            SimpleIoc.Default.Register<Graphics>();

  
        }

        /// <summary>
        /// Gets the Main property.
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        
        // Home View Models
        public List<IHomeBaseViewModel> HomePivots 
        {
            get 
            {
                List<IHomeBaseViewModel> list = new List<IHomeBaseViewModel>();
                list.Add(ServiceLocator.Current.GetInstance<PlanningViewModel>());
                list.Add(ServiceLocator.Current.GetInstance<ShoppingViewModel>());
                list.Add(ServiceLocator.Current.GetInstance<MoreViewModel>());
                return list;
            }
        }

        // Planning View Model
        public PlanningViewModel PlanningPivot
        {
            get
            {
                return ServiceLocator.Current.GetInstance<PlanningViewModel>();
            }
        }

        // Shopping View Model
        public ShoppingViewModel ShoppingPivot
        {
            get
            {
                return ServiceLocator.Current.GetInstance<ShoppingViewModel>();
            }
        }
        // More View Model
        public MoreViewModel MorePivot
        {
            get
            {
                return ServiceLocator.Current.GetInstance<MoreViewModel>();
            }
        }

        // Store View Model
        public StoresViewModel StoresList
        {
            get
            {
                return ServiceLocator.Current.GetInstance<StoresViewModel>();
            }
        }

        // CouponsList ViewModel
        public CouponsListViewModel CouponsList
        {
            get
            {
                return ServiceLocator.Current.GetInstance<CouponsListViewModel>();
            }
        }

        // CouponDetails ViewModel
        public CouponDetailsViewModel CouponDetails
        {
            get
            {
                return ServiceLocator.Current.GetInstance<CouponDetailsViewModel>();
            }
        }

        // WebBrowser View Model
        public WebBrowserViewModel WebBrowser
        {
            get
            {
                return ServiceLocator.Current.GetInstance<WebBrowserViewModel>();
            }
        }

        // Localization
        public Localization LocalizedStrings
        {
            get
            {
                return ServiceLocator.Current.GetInstance<Localization>();
            }
        }

        // Graphics
        public Graphics GraphicResources
        {
            get
            {
                return ServiceLocator.Current.GetInstance<Graphics>();
            }
        }

        /// <summary>
        /// Cleans up all the resources.
        /// </summary>
        public static void Cleanup()
        {
        }
    }
}